const lodash = require("lodash");
const fs = require("fs-extra");
const path = require("path");
const arrayMode = require("ml-array-mode");
const DesertData = require("./DihorOtok_Main_Squad_KillGroggyBluezone.json");
const MAP_SIZE = 612000;//CM
const GRID_LENGTH = 7650;//CM
const MatchesCount = 90;
const GRIDS = (_ => {
  let length = MAP_SIZE / GRID_LENGTH;
  let arr = new Array(length);
  for (let i = 0; i < length; i++) {
    arr[i] = (new Array(length)).fill(0);
  }
  return arr;
})();


for (let ev of DesertData.DIE_EVS) {
  let victimPos = ev.victim.location;
  let xi = Math.floor(victimPos.x / GRID_LENGTH);
  let yi = Math.floor(victimPos.y / GRID_LENGTH);
  GRIDS[xi][yi] += 1;
  // debugger
}
for (let ev of DesertData.GROGGY_EVS) {
  let victimPos = ev.victim.location;
  let xi = Math.floor(victimPos.x / GRID_LENGTH);
  let yi = Math.floor(victimPos.y / GRID_LENGTH);
  GRIDS[xi][yi] += 1;
  // debugger
}
let flatGrids = lodash.flatten(GRIDS)
let max = lodash.max(flatGrids);
debugger
let test = (_ => {
  let obj = {};
  for (let v of flatGrids) {
    if (!obj[v]) {
      obj[v] = 0;
    }
    obj[v] += 1;
  }
  debugger
})();
for (let i = 0; i < GRIDS.length; i++) {
  for (let j = 0; j < GRIDS[i].length; j++) {
    if (GRIDS[i][j] > 0) {
      GRIDS[i][j] = GRIDS[i][j] / MatchesCount;
    }
  }
}
fs.writeFile(path.join(__dirname, "DihorOtokMap_VictimsDistribution_7650cm.json"), JSON.stringify(GRIDS), (err) => {
  debugger
});
debugger